import re
from python_baway.common.xcommon import sep


def xdisplay_match(xmatch):
    if xmatch is None:
        return None
    return f'<Match: {xmatch.group()!r}, groups = {xmatch.groups()}>'


sep('is valid cards in hand')
xvalid = re.compile(r'^\s*([a2-9tjqk]{5})\s*$', re.IGNORECASE)

print(xdisplay_match(xvalid.match('akt5Q')))
print(xdisplay_match(xvalid.match('akt5e')))
print(xdisplay_match(xvalid.match('akt')))
print(xdisplay_match(xvalid.match('727Ak')))

sep('is paired')
xpair = re.compile(r'(.+).*\1', re.IGNORECASE)

print(xdisplay_match(xpair.search('717ak')))
print(xdisplay_match(xpair.search('718ak')))
print(xdisplay_match(xpair.search('354aA')))
print(xdisplay_match(xpair.search('354AA')))
print(xdisplay_match(xpair.search('3A54A')))

sep('What is in the pair?')
xmatch = xpair.search('3a54A')
print(xmatch.group(0))
print(xmatch.group(1))
